<?php
defined('ANT_ACCESS') or die('Access denided');
/**
 * Ant Framework
 *
 * An open source application development framework for PHP 5
 *
 * @package		Ant Framework
 * @author		Meshin Dmitriy
 * @copyright	Copyright (c) 2008, Meshin Dmitriy
 * @license		GNU Public Lisence v2
 * @link		http://code.google.com/p/ant-framework
 * @desc		Loader class
 **/
	class ANT_loader{
		protected $controller;

		function __construct(){
			$this->controller =& get_instance();
		}
		
		protected function load($name, $type, $system = TRUE){
			if(is_string($name)){
				if(TRUE === $system){
					require_once(get_folder('sys_'.$type).$name.EXT);
				}
				else
				{
					require_once(get_folder($type).$name.EXT);
				}
			}
			elseif(is_array($name)){
				foreach($name as $item){
					if(TRUE === $system){
						require_once(get_folder('sys_'.$type).$item.EXT);
					}
					else
					{
						require_once(get_folder($type).$item.EXT);
					}
				}
			}
			else trigger_error('Loader: '.$name.' is not array or string', E_USER_ERROR);
		}

		public function plugin($name, $sys = TRUE){
			$this->load($name, 'plugins', (boolean)$sys);
		}
		
		public function library($name, $sys = TRUE){
			$this->load($name, 'libs', (boolean)$sys);
			if(is_array($name)){
				foreach($name as $class){
					$this->controller->$class = load_class($class, (boolean)$sys);
				}
			}
			else $this->controller->$name = load_class($name, (boolean)$sys);
		}
		
		public function helper($name, $sys = TRUE){
			$this->load($name, 'helpers', (boolean)$sys);
		}
		
		public function language($name){
			$this->load($name, 'language', FALSE);
		}
	}
?>